package com.wowangz.cms.topic.column.service;

import java.util.List;
import java.util.Map;

import com.wowangz.cms.common.utils.SysConstant;
import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.topic.column.entity.Column;

/**
 * 
 * @author HUANGYUAN
 *	专题栏目操作类
 */
public class ColumnService extends BaseService{

	/**
	 * 保存栏目信息
	 * @param column
	 * @throws ServiceException
	 */
	public void saveColumn(Column column) throws ServiceException{
		try {
			this.getSqlSession().insert("Column.saveColumn", column);			
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 修改栏目信息
	 * @param column
	 */
	public void updateColumn(Column column) throws ServiceException{
		try {
			this.getSqlSession().update("Column.updateColumn", column);			
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 删除栏目
	 * @param column
	 */
	public void deleteColumn(Column column) throws ServiceException{
		try {
			this.getSqlSession().update("Column.updateColumn", column);			
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 查询一条栏目信息
	 * @param map
	 * @return
	 */
	public Column findOneColumnByMap(Map<String, Object> map) throws ServiceException{
		map.put("statusid", SysConstant.RecordStatus.VALID);
		try {
			List<Object> objects = this.getSqlSession().selectList("Column.findColumnById", map);	
			return objects != null ? (Column) objects.get(0): null;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 查询记录总数
	 * @param map
	 * @return
	 */
	public Long findColumnCountByMap(Map<String, Object> map){
		try {
			map.put("statusid", SysConstant.RecordStatus.VALID);
			Long count = this.getSqlSession().selectOne("Column.findColumnCountByMap", map);	
			return count;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 查询集合数据
	 * @param map
	 * @return
	 */
	public List<Column> findColumnByMap(Map<String, Object> map) throws ServiceException{
		try {
			map.put("statusid", SysConstant.RecordStatus.VALID);
			List<Column> columns = this.getSqlSession().selectList("Column.findColumnByMap", map);	
			return columns;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 查询所有的栏目
	 * @param map
	 * @return
	 */
	public List<Column> findAllColumnByMap(Map<String, Object> map) throws ServiceException{
		try {
			map.put("statusid", SysConstant.RecordStatus.VALID);
			List<Column> columns = this.getSqlSession().selectList("Column.findAllColumnByMap", map);	
			return columns;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
}
